package com.KKd.controller;

import com.KKd.pojo.User;
import com.sun.deploy.net.HttpResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 14587
 * @date 2020/11/6 9:34
 */
@RestController//不经过视图解析器，直接返回json字符串
public class AjaxController {
    @RequestMapping("/t1")
    public String test(){
        return "hello";
    }

    @RequestMapping("/a1")
    public void a1(String username, HttpServletResponse httpServletResponse) throws IOException {
        System.out.println(username);
        if ("dou".equals(username)){
            httpServletResponse.getWriter().write("true");
        }
        else {
            httpServletResponse.getWriter().write("false");
        }
    }

    @RequestMapping("/a2")
    public List<User> a2(){
        List<User> userList=new ArrayList<User>();
        userList.add(new User("dou",20,"男"));
        userList.add(new User("wang",20,"女"));
        userList.add(new User("dan",20,"女"));
        return userList;
    }

    @RequestMapping("/a3")//逻辑不对，随便写写
    public String a3(String name,String password){
        String msg="";
        if ("admin".equals(name)){
            msg="ok";
            if ("123456".equals(password)){
                msg="ok";
                return msg;
            }
            else{
                msg="密码有误";
                return msg;
            }
        }
        else{
            msg="用户名有误";
        }

        return msg;
    }
}
